﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PriceCust.aspx.cs" Inherits="Skyworth.CRM.Web.SalesManagement.PriceCust" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>设置价格政策内客户</title>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <%--[if IE]>
     <link href="../themes/css/ieHack.css" rel="stylesheet" type="text/css" />
    <![endif]--%>
    <link href="../themes/default/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/wbox.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />

    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>

    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>

    <script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>

    <script src="../javascripts/wbox.js" type="text/javascript"></script>

    <style type="text/css">
        .content
        {
            overflow: auto;
            border: solid 1px #CCC;
            line-height: 21px;
            background: #FFF;
            padding: 2px;
        }
    </style>

    <script type="text/javascript">
        var addWindow;
        var policyId=<%=PolicyId %>;
        var txt =$("#txtCode");
        //下一页
        function dwzPageBreak(args) {
            $("#policyPanel #pageNum").val(args["pageNum"]);
            $("#policyPanel #selectedId").val("");
            GetPolicyCusts();
        }

        //设置翻页    
        function SetPager(pagerId, pageMsgId, numPerPage, currentPage, totalRecords, totalPages) {
            $(pageMsgId).text("  共【" + totalRecords + "】条，【" + totalPages + "】页");

            $(pagerId).each(function() {
                var $this = $(this);
                $this.pagination({
                    targetType: $this.attr("targetType"),
                    totalCount: totalRecords,
                    numPerPage: numPerPage,
                    pageNumShown: $(this).attr("pageNumShown"),
                    currentPage: currentPage
                });
            });
        }
        
        
        function DeleteCust(Id) {
            var paramList = '{"custId":"' + Id + '","policyId":"'+policyId+'"}';
            $.ajax({
                type: "POST",
                url: "PriceCust.aspx/DeleteCust",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function(data) {
                    if (data.d) {
                        GetPolicyCusts();
                    }
                },
                error: function(msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，删除价格政策内客户失败！", Icon: IconType.Warning }); }
            })
        }

        function GetPolicyCusts() {
            var paramList = '{"code":"' + $("#txtCode").val() + '","name":"' + $("#txtName").val() + '","orderField":"' 
            + $("#orderField").val() + '","orderValue":"' + $("#orderValue").val() + '","pageIndex":"' 
            + $("#pageNum").val() + '","pagePerSize":"' + $("#numPerPageSelect").val() +'","policyId":"'+policyId+'"}';
           
            $.ajax({
                type: "POST",
                url: "PriceCust.aspx/GetPolicyCusts",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function(data) {
                    var dataTable = jQuery.parseJSON(data.d);
                    //填充数据
                    $("#pricePolicyTable tbody").empty();
                    var lists = "";
                    $.each(dataTable.rows, function(i, item) {
                        lists = lists + "<tr rel='" + item.FItemId + "'>" +
                        "<td>" + item.FNumber + "</td>" +
                        "<td>" + item.FName + "</td>" +
                        "<td>" + item.FDree + "</td>" +
                        "<td>" + item.FMobil + "</td>" +
                        "<td>" + item.FQH + "</td>" +
                        "<td>" + item.FTel + "</td>" +
                        "<td>" + item.LevelName +"</td>" +
                        "</tr>";
                    })
                    $(lists).appendTo($("#pricePolicyTable tbody"));

                    //绑定事件
                    $("#pricePolicyTable tr:nth-child(even)").attr('class', "trbg");
                    $("#pricePolicyTable tbody tr").click(function() {
                        $("#policyPanel #selectedId").val($(this).attr("rel"));
                        $(this).addClass("selected");
                        $(this).siblings("tr").removeClass("selected");
                    }).hover(function() {
                        $(this).addClass('hover');
                    }, function() {
                        $(this).removeClass('hover');
                    })

                    SetPager("#policyPanel div.pagination", "#policyPanel #pageMsg", $("#policyPanel #numPerPageSelect").val(), $("#policyPanel #pageNum").val(), dataTable.totalRecords, dataTable.totalPages);

                },
                error: function(msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，获取数据失败！", Icon: IconType.Warning }); },
                beforeSend: function(){$("#LoadingPanel").fadeIn("slow");},
                complete: function(){$("#LoadingPanel").fadeOut("fast");}
            })

        }

        $(document).ready(function() {           

            GetPolicyCusts();

            $("#btnSearch").click(function() {
                GetPolicyCusts();
                return false;
            })

            $("div.panelBar li").hover(function() { $(this).addClass("hover"); },
                                     function() { $(this).removeClass("hover"); })

            $("#policyPanel #numPerPageSelect").change(function() {
                $("#policyPanel #pageNum").val(1);
                $("#policyPanel #selectedId").val("");
                GetPolicyCusts();
            })

            // init styles
            $("input[type=text][id!='txtCustName']").addClass("textInput").focusClass("focus");

            $("#btnDelete").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var custId = $("#selectedId").val();
                    var selectedLength = $("#pricePolicyTable tbody tr.selected").length;
                    if (parseInt(custId) > 0 && selectedLength > 0) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '你确定要移除该客户吗？', Icon: IconType.Question,
                            Oncallback: function(IsYes, Id) {
                                if (IsYes) { DeleteCust(custId); }
                            }
                        })
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要移除的政策内客户！", Icon: IconType.Warning });
                    }
                    return false;
                }
            })



            $("#pricePolicyTable thead th[colName]").click(function() {
                $("#policyPanel #orderField").val($(this).attr("colName"));
                if ($(this).hasClass("headerSortUp")) {
                    $("#policyPanel #orderValue").val("desc");
                    $(this).removeClass("headerSortUp").addClass("headerSortDown");
                }
                else {
                    $("#policyPanel #orderValue").val("asc");
                    $(this).removeClass("headerSortDown").addClass("headerSortUp");
                }
                $(this).siblings("th").removeClass("headerSortUp").removeClass("headerSortDown");
                $("#policyPanel #pageNum").val(1);
                GetPolicyCusts();
            })



    $("#btnAdd").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    addWindow = $("#selectedId").wBox({ title: "新增价格政策", requestType: "iframe", target: "SelectCust.aspx?Type=add&policyId="+policyId, iframeWH: { width: 680, height: 350} });
                    addWindow.showBox();
                }
                return false;
            })
            

        })
        
      
        

        
        
        

    
    </script>

</head>
<body style="background-color: #FFF">
    <form id="form1" runat="server">
    <div>
        <div style="margin: 2px;">
            <div class="panel" id="policyPanel">
                <div class="panelHeader">
                    <div class="panelHeaderContent">
                        <h1>
                            <span style="color: #FF0000; font-weight: bold">
                                <asp:Label ID="txtPolicyName" runat="server" Text=""></asp:Label></span>设置价格政策内客户</h1>
                    </div>
                </div>
                <div class="panelContent">
                    <div class="content">
                        <table width="100%" id="policy">
                            <tr>
                                <td>
                                    <div class="searchBar" style="padding: 4px 5px;">
                                        <ul>
                                            <li style="float: left;"><span>客户名称：</span>
                                                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                                            </li>
                                            <li style="float: left; padding-left: 10px;"><span>客户编码：</span>
                                                <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
                                            </li>
                                            <li style="float: left; padding-left: 20px">
                                                <div class="buttonActive">
                                                    <div class="buttonContent">
                                                        <asp:Button ID="btnSearch" runat="server" Text="查询" ToolTip="查询价格政策内客户信息" CssClass="serverButton" />
                                                    </div>
                                                </div>
                                            </li>
                                            <br style="clear: both" />
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div>
                                        <div class="panelBar">
                                            <ul class="toolBar">
                                               <li class="">
                                                    <asp:LinkButton ID="btnAdd" runat="server" CssClass="add"><span>添加</span> </asp:LinkButton></li>
                                                <li class="line">line</li>
                                                <li class="">
                                                    <asp:LinkButton ID="btnDelete" runat="server" CssClass="delete"><span>移除</span> </asp:LinkButton></li>
                                                <li class="line">line</li>
                                                <li class="">
                                                    <input type="hidden" style="display: none;" id="selectedId" runat="server" />
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div style="_margin-top: -2px;">
                                        <div class="tableList">
                                            <table class="list" width="100%" id="pricePolicyTable">
                                                <thead>
                                                    <tr>
                                                        <th width="120" valign="middle" style="cursor: pointer;" colname="FNumber">
                                                            <span style="float: left">客户编码</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FName" class="headerSortUp">
                                                            <span style="float: left">客户名称</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FDree">
                                                            <span style="float: left">详细地址</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FMobil">
                                                            <span style="float: left">手机号</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FQH">
                                                            <span style="float: left">区号</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FTel">
                                                            <span style="float: left">电话</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                        <th valign="middle" style="cursor: pointer;" colname="FJB">
                                                            <span style="float: left">客户等级</span> <span style="float: right;" class="sortIcon">
                                                            </span>
                                                        </th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                </tbody>
                                                <tfoot>
                                                </tfoot>
                                            </table>
                                        </div>
                                        <div class="panelBar">
                                            <div class="pages">
                                                <span>每页显示</span>
                                                <div style="float: left">
                                                    <select id="numPerPageSelect" runat="server">
                                                        <option>1</option>
                                                        <option>2</option>
                                                        <option>15</option>
                                                        <option>20</option>
                                                        <option>25</option>
                                                        <option selected="selected">30</option>
                                                        <option>35</option>
                                                        <option>40</option>
                                                        <option>45</option>
                                                        <option>50</option>
                                                    </select>
                                                </div>
                                                <span id="pageMsg"></span>
                                            </div>
                                            <div class="pagination" targettype="navTab" pagenumshown="3">
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <input type="hidden" id="pageNum" name="pageNum" value="1" runat="server" />
                                    <input type="hidden" id="orderField" name="orderField" value="FName" runat="server" />
                                    <input type="hidden" id="orderValue" name="orderValue" value="asc" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="panelFooter">
                    <div class="panelFooterContent">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="LoadingPanel" style="display: none;">
        <div id='background' class='background'>
        </div>
        <div id='progressBar' class='progressBar'>
            数据加载中，请稍等...</div>
    </div>
    <input id="hideCustIds" type="hidden" runat="server" value="" />
    </form>
</body>
</html>
